home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Applications / Mic-1 v1.0 / Project and Source / Source / mic_control.cpp < prev    next >
Text File  |  1996-05-15  |  6KB  |  231 lines

  1. /*
  2.     "mic_control.cpp"
  3.     
  4.     This file contains Mic-1 objects which fall in the "control" catagory, such as
  5.     the Microinstruction Register and Control Store
  6. */
  7.  
  8. #include <iostream.h>
  9. #include <fstream.h>
  10. #include <iomanip.h>
  11.  
  12. #include "mic_main.h"
  13. #include "mic_control.h"
  14. #include "mic_global_functions.h"
  15.  
  16. const unsigned short kMaxControlStore = 256;
  17.  
  18. #pragma mark ••• MMUX •••
  19.  
  20. void MMUXClass::output(Mic_1_Class& Mic)
  21. {
  22.     if (Jump)
  23.         Mic.MPC.input_MMUX(Address_word);
  24.     else // don't jump, just go ahead with the next instruction
  25.         Mic.MPC.input_MMUX(Incrementer_word);
  26. }
  27.  
  28. ostream& operator << (ostream& s, MMUXClass& m)
  29. {
  30.     s << hex << uppercase;
  31.     s << "MMUX:" << endl;
  32.     s << "  Jump: " << m.Jump << endl;
  33.     s << "  Incrementer_word: " << setw(4) << setfill('0') << right << m.Incrementer_word << endl;
  34.     s << "  Address_word: " << setw(4) << setfill('0') << right << m.Address_word << endl;
  35.     s << resetiosflags(ios::hex | ios::uppercase);
  36.     return s;
  37. }
  38.  
  39. #pragma mark ---------------------------------
  40. #pragma mark ••• MPC •••
  41.  
  42. void MPCClass::output (Mic_1_Class& Mic)
  43. {
  44.     Mic.ControlStore.input_MPC(Mic, word);
  45.     Mic.Incrementer.input_MPC(Mic, word);
  46. }
  47.  
  48. ostream& operator << (ostream& s, MPCClass& m)
  49. {
  50.     s << hex << uppercase;
  51.     s << "MPC: " << setw(4) << setfill('0') << right << m.word << endl;
  52.     s << resetiosflags(ios::hex | ios::uppercase);
  53.     return s;
  54. }
  55.  
  56. #pragma mark ---------------------------------
  57. #pragma mark ••• INCREMENTER •••
  58.  
  59. void IncrementerClass::output(Mic_1_Class& Mic)
  60. {
  61.     Mic.MMUX.input_Incrementer(Mic, word + 1);
  62. }
  63.  
  64. #pragma mark ---------------------------------
  65. #pragma mark ••• CONTROL STORE •••
  66.  
  67. short InitMicControl (Mic_1_Class& Mic)
  68. {
  69.     Str32 fileNameStr;
  70.     char *fileNameP;
  71.     GetIndString(fileNameStr, 129, 2);
  72.     fileNameP = P2CStr(fileNameStr);
  73.     ifstream ControlInitFile(fileNameP);
  74.     
  75.     for (int n=0; n<kMaxRAM; n++)
  76.         Mic.ControlStore.putNthWord (n,0);
  77.     
  78.     if (ControlInitFile.is_open())
  79.     {
  80.         ControlInitFile >> Mic.ControlStore;
  81.         // initialize the MIR to the first Microprogram instruction
  82.         Mic.ControlStore.output(Mic);
  83.         Mic.Incrementer.output(Mic);
  84.     }
  85.     else
  86.     {
  87.         return 132;    // error alert code saying you're in bad shape
  88.     }
  89.     return 0;
  90. }
  91.  
  92. unsigned long ControlStoreClass::getNthWord (short n)
  93. {
  94.     if ((n>=0) && (n<kMaxControlStore))
  95.     {
  96.         return store[n];
  97.     }
  98.     else
  99.         return 0;
  100. }
  101.  
  102. Boolean ControlStoreClass::putNthWord (short n, unsigned long newWord)
  103. {
  104.     if ((n>=0) && (n<kMaxControlStore))
  105.     {
  106.         store[n] = newWord;
  107.         return true;
  108.     }
  109.     else
  110.         return false;
  111. }
  112.  
  113. void ControlStoreClass::output (Mic_1_Class& Mic)
  114. {
  115.     Mic.MIR.input_ControlStore(getNthWord(Index));
  116. }
  117.  
  118. ostream& operator << (ostream& s, ControlStoreClass& c)
  119. {
  120.     short numRows = 80;
  121.     
  122.     s << "CONTROL STORE:" << endl;
  123.     for (int i=0; i<numRows; i++)
  124.     {
  125.         s << setw(3) << i << " ";
  126.         s << hex << uppercase;
  127.         s << setw(8) << setfill('0') << c.getNthWord(i);
  128.         s << resetiosflags(ios::hex | ios::uppercase);
  129.         s << endl;
  130.     }
  131.     if (numRows < kMaxControlStore)
  132.         s << endl << "<abbreviated>" << endl;
  133.     return s;
  134. }
  135.  
  136. istream& operator >> (istream& s, ControlStoreClass& c)
  137. {
  138.     unsigned long word = 1;
  139.     short counter = 0;
  140.     
  141.     while ((counter < kMaxControlStore) && word)
  142.     {
  143.         s >> word;
  144.         s >> hex >> uppercase >> word;
  145.         s >> resetiosflags(ios::hex | ios:: uppercase);
  146.         c.putNthWord(counter++, word);
  147.     }
  148.     for (int i=counter; i<kMaxControlStore; i++)
  149.         c.putNthWord(i,0);
  150.     return s;
  151. }
  152.  
  153. #pragma mark ---------------------------------
  154. #pragma mark ••• MIR •••
  155.  
  156. /*
  157.        The MicroInstruction Register
  158. ______________________________________________
  159. |A|C |A |S |M|M|R|W|E|    |    |    |        |
  160. |M|O |L |H |B|A|D|R|N| C  | B  | A  | ADDR   |
  161. |U|N |U |  |R|R| | |C|    |    |    |        |
  162. |X|D |  |  | | | | | |    |    |    |        |
  163. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  164. AMUX - controls left ALU input:            (0 = A latch, 1 = MBR)
  165. COND - controls microprogram jump        (0 = no jump, 1 = jump if negative,
  166.                                                                          2 = jump if zero, 3 = jump unconditionally)
  167. ALU - ALU function:                                    (0 = A + B, 1 = A AND B, 2 = A, 3 = ~A)
  168. SH - shifter function:                            (0 = no shift, 1 = shift left, 2 = shift right)
  169. MBR - loads mbr from shifter:                (0 = don't load mbr, 1 = load mbr)
  170. MAR - loads mar from b latch:                (0 = don't load mar, 1 = load mar)
  171. RD - requests memory read:                    (0 = no read, 1 = load mbr from memory)
  172. WR - requests memory write:                    (0 = no write, 1 = write mbr to memory)
  173. ENC - controls storing into scratchpad (0 = don't store, 1 = store)
  174. C - selects register for storing into if ENC = 1    (16 options)
  175. B - selects B bus source                        (16 options)
  176. A - selects A bus source                        (16 options)
  177. */
  178.  
  179. void MIRClass::output(Mic_1_Class& Mic)
  180. {
  181.     Mic.AMUX.input_MIR                            ((unsigned short)((MIR & 0x80000000) >> 31));
  182.     Mic.MicroSeq.input_MIR                    ((unsigned short)((MIR & 0x60000000) >> 29));
  183.     Mic.ALU.input_MIR                                ((unsigned short)((MIR & 0x18000000) >> 27));
  184.     Mic.Shifter.input_MIR                        ((unsigned short)((MIR & 0x06000000) >> 25));
  185.     Mic.MBR.input_MIR_enable                ((unsigned short)((MIR & 0x01000000) >> 24));
  186.     Mic.MAR.input_MIR                                ((unsigned short)((MIR & 0x00800000) >> 23));
  187.     Mic.MBR.input_MIR_read                    ((unsigned short)((MIR & 0x00400000) >> 22));
  188.     Mic.MBR.input_MIR_write                    ((unsigned short)((MIR & 0x00200000) >> 21));
  189.     Mic.ScratchPad.input_MIR_enable    ((unsigned short)((MIR & 0x00100000) >> 20));
  190.     Mic.ScratchPad.input_MIR_C            ((unsigned short)((MIR & 0x000F0000) >> 16));
  191.     Mic.ScratchPad.input_MIR_B    (Mic,(unsigned short)((MIR & 0x0000F000) >> 12));
  192.     Mic.ScratchPad.input_MIR_A    (Mic,(unsigned short)((MIR & 0x00000F00) >> 8));
  193.     Mic.MMUX.input_MIR                    (Mic,(unsigned short)((MIR & 0x000000FF) >> 0));
  194. }
  195.  
  196. ostream& operator << (ostream& s, MIRClass& m)
  197. {
  198.     s << hex << uppercase;
  199.     s << "MIR: " << setw(8) << setfill('0') << m.MIR << endl;
  200.     s << resetiosflags(ios::hex | ios::uppercase);
  201.     return s;
  202. }
  203.  
  204. #pragma mark ---------------------------------
  205. #pragma mark ••• MICRO SEQUENCER •••
  206.  
  207. void MicroSeqClass::output(Mic_1_Class& Mic)
  208. {
  209.     short jump = false;
  210.     switch(jump_cond)
  211.     {
  212.         case(0): break;
  213.         case(1): if (negative) jump = true; break;
  214.         case(2): if (zero) jump = true; break;
  215.         case(3): jump = true; break;
  216.     }
  217.     Mic.MMUX.input_MicroSeq(Mic, jump);
  218. }
  219.  
  220. ostream& operator << (ostream& s, MicroSeqClass& m)
  221. {
  222.     short zero;
  223.     short negative;
  224.     short jump_cond;
  225.     
  226.     s << "MICRO SEQUENCER:" << endl;
  227.     s << "  ZERO: " << m.zero << endl;
  228.     s << "  NEG: " << m.negative << endl;
  229.     s << "  JUMP COND: " << jump_cond << endl;
  230.     return s;
  231. }